//实现由先序、中序序列构造二叉树的算法
/* 
设一棵二叉树以二叉链表表示，试编写有关二叉树的递归算法：
1.统计二叉树中度为1的结点个数
2.统计二叉树中度为1的结点个数
3.统计二叉树中度为0的结点个数 
4.统计二叉树的高度
5.统计二叉树的宽度，即在二叉树的各层上具有结点数最多的那一层上结点总数
6.计算二叉树中各结点中的最大元素的值
7.交换每个结点的左孩子结点和右孩子结点
8.从二叉树中删去所有叶结点*/

/*判断是否为完全二叉树*/
#include<iostream>
#include<fstream>
#include<string>
#include"BinaryTree.h"
using namespace std;

int main()
{
    fstream file;
    file.open("BiTreePre.txt",ios::in);
    string preOrderString;
    string midOrderString;
    file>>preOrderString;
    cout<<"preOrderString:"<<preOrderString<<endl;
    file>>midOrderString;
    cout<<"midOrderString:"<<midOrderString<<endl;
    file.close();
    BinaryTree * binarytree = new BinaryTree;
    binarytree->CreateBiTreeInMid(binarytree->root,preOrderString,midOrderString);
    //cout<<binarytree->root->value<<endl;
    cout<<"Start MideSearchi"<<endl;
    binarytree->MidSearchBiTree(binarytree->root);
    cout<<endl;
    cout<<"Du is 1:"<<binarytree->TreeNode1Sum(binarytree->root)<<endl;
    cout<<"Du is 0:"<<binarytree->TreeNode0Sum(binarytree->root)<<endl;
    cout<<"Du is 2:"<<binarytree->TreeNode2Sum(binarytree->root)<<endl;
    cout<<"Height is "<<binarytree->GetTheHeight()<<endl;
    cout<<"Width is "<<binarytree->GetTheWidth()<<endl;
    cout<<"Is it CompleteBinaryTree? "<<binarytree->JudgeComplete()<<endl;
    binarytree->SwapTheBinaryTree(binarytree->root);
    binarytree->MidSearchBiTree(binarytree->root);
    cout<<endl;
    delete binarytree;
    return 0;
}
